import { defineConfig } from "vite"
import uni from "@dcloudio/vite-plugin-uni"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { UniUseAutoImports } from "@uni-helper/uni-use"
import { fileURLToPath } from "url"
import tailwindcss from "tailwindcss"
import autoprefixer from "autoprefixer"
import postCssPxToRem from "postcss-pxtorem"

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    AutoImport({
      imports: [
        "@vueuse/core",
        UniUseAutoImports, // 放在 @vueuse/core 之后以覆盖同名方法
      ],
      dts: fileURLToPath(new URL("./types/auto-imports.d.ts", import.meta.url)),
    }),
    Components({
      dts: fileURLToPath(new URL("./types/components.d.ts", import.meta.url)),
      dirs: [
        fileURLToPath(new URL("./src/thorui/components", import.meta.url)),
      ],
    }),
    uni(),
  ],
  css: {
    postcss: {
      plugins: [
        tailwindcss,
        autoprefixer,
        postCssPxToRem({
          rootValue: 37.5,
          propList: ["*"],
        }),
      ],
    },
  },
})
